package SimpleSelenium;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

/**
 * Created with IntelliJ IDEA.
 * User: dmytro.v.kozlov
 * Date: 7/2/13
 * Time: 4:32 PM
 * To change this template use File | Settings | File Templates.
 */
public class POMainPage extends BaseTest {

    public POMainPage(WebDriver driver) {
        this.driver = driver;
    }

    public void waitWhileGettingDeviceParams() {
        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.textToBePresentInElement(By.cssSelector("div#cambui_stat_20 > label.stat_label")
                , "Cambium-STA"));

    }

    public void waitAfterLogin() {
        WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("bbmenu"))));
//        System.out.println("Found overlay, sleep "+ExpectedConditions.presenceOfElementLocated(By.id("overlay")));
//        wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.id("overlay"))));
//        System.out.println("Overlay Closed" +ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.id("overlay"))));
    }

    public void login(String username, String pass) {
        driver.findElement(By.name("username")).sendKeys(username);
        driver.findElement(By.name("password")).sendKeys(pass);
        driver.findElement(By.cssSelector(" button.btn")).click();


    }

    public void Ping(String ip) {
        driver.findElement(By.xpath("/html/body/table/tbody/tr/td/div[3]/a[5]/div[2]")).click();
        driver.findElement(By.xpath("//*[@id=\"cambui_page_2_leftmenu\"]/a[5]/div[2]")).click();
        driver.findElement(By.xpath("/html/body/table/tbody/tr[2]/td[2]/div/div[3]/div[5]/div[2]/div/input")).sendKeys(ip);
        driver.findElement(By.xpath("/html/body/table/tbody/tr[2]/td[2]/div/div[3]/div[5]/div[2]/div[5]/a")).click();

    }

    public void ThroutputTest(String ip) {
        driver.findElement(By.xpath(".//*[@id=\"cambui_page_2_leftmenu\"]/a[4]/div[2]")).click();
        driver.findElement(By.xpath(".//*[@id='cambui_input_45']/input")).sendKeys(ip);
        driver.findElement(By.xpath(".//*[@id='cambui_button_5']/a")).click();
    }

    public void waitPingResults() {
        wait.until(ExpectedConditions.textToBePresentInElement(By.xpath(".//*[@id='cambui_richtext_2']/div/pre")
                , "PING"));
    }
}

